<?php

use yii\helpers\Url;
use backend\models\service\Bill;
use backend\widgets\GridView;

$this->registerCssFile(Url::to('@web/css/common/daterangepicker-bs3.css'));
$this->registerCssFile(Url::to('@web/css/PassList.css'));
$this->title = '首页';
?>
<script type="text/javascript" src="<?php echo Yii::$app->homeUrl; ?>js/extendPagination.js"></script>
<script type="text/javascript" src="<?php echo Yii::$app->homeUrl; ?>js/moment.js"></script>
<script type="text/javascript" src="<?php echo Yii::$app->homeUrl; ?>js/daterangepicker.js"></script>
<div class="RightCenter clear">
    <div class="RightTime">
        <div class="Time">
            <h3>首页</h3>
        </div>
    </div>
    <div class="row clear">
        <div class="count count_One">
            <k>今日充值金额</k>
            <div>
                <?php echo (Bill::getReChargeMoney($type = 1)['pay_money']>0?Bill::getReChargeMoney($type = 1)['pay_money']:0); ?>
                <h5><?php echo Bill::getReChargeMoney($type = 1)['n']; ?>次</h5>
            </div>
        </div>
        <div class="count count_Tow">
            <k>昨日充值金额</k>
            <div>
                <?php echo (Bill::getReChargeMoney($type = 2)['pay_money']>0?Bill::getReChargeMoney($type = 2)['pay_money']:0); ?>
                <h5><?php echo Bill::getReChargeMoney($type = 2)['n']; ?>次</h5>
            </div>
        </div>

        <div class="count count_three">
            <k>本周充值金额</k>
            <div>
                <?php echo (Bill::getReChargeMoney($type = 3)['pay_money']>0?Bill::getReChargeMoney($type = 3)['pay_money']:0); ?>
                <h5><?php echo Bill::getReChargeMoney($type = 3)['n']; ?>次</h5>
            </div>
        </div>

        <div class="count count_four">
            <k>本月充值金额</k>
            <div>
                <?php echo (Bill::getReChargeMoney($type = 4)['pay_money']>0?Bill::getReChargeMoney($type = 4)['pay_money']:0); ?>
                <h5><?php echo Bill::getReChargeMoney($type = 4)['n']; ?>次</h5>
            </div>
        </div>

        <div class="count count_five">
            <k>累计账户总额</k>
            <div>
                <?php echo (Bill::getReChargeMoney($type = 5)['pay_money']>5?Bill::getReChargeMoney($type = 5)['pay_money']:0); ?>
                <h5><?php echo Bill::getReChargeMoney($type = 5)['n']; ?>次</h5>
            </div>
        </div>
    </div>


    <div class="Read_date">
        <ul>
            <li class="Read_LisJ">
                <span data-type="1" <?php echo $params['daily_type'] == 1 ? 'class="Read_Span"' : '';?>>周</span>
                <span data-type="2" <?php echo $params['daily_type'] == 2 ? 'class="Read_Span"' : '';?>>月</span>
                <span data-type="3" <?php echo $params['daily_type'] == 3 ? 'class="Read_Span"' : '';?>>全部</span>
            </li>
            <li class="input-prepend input-group Read_inpuT">
                <span class="add-on input-group-addon Read_IN"></span>
                <input type="text" readonly name="birthday" id="reservation" class="form-control form-controlCLOC" />
                <b class="caret"></b>
            </li>
        </ul>
    </div>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'id' => 'grid',
        'columns' => [
            [
                'class' => 'yii\grid\CheckboxColumn',
                'headerOptions' => ['width' => 5],
                'checkboxOptions' => function($model, $key, $index, $column) {
                    if (isset($_COOKIE['id'])) return ['checked'=>in_array($model->id, $_COOKIE['id']) ? 'checked' : ''];
                }
            ],
            [
                'contentOptions' => ['class' => 'TR_Tows'],
                'label' => '时间',
                'headerOptions' => ['width' => 10],
                'value' => function($data){
                    return $data['day'];
                }
            ],
            [
                'label' => '充值金额',
                'headerOptions' => ['width' => 10],
                'value' => function($data){
                    return $data['total_money'];
                }
            ],
            [
                'label' => '充值笔数',
                'headerOptions' => ['width' => 5],
                'value' => function($data){
                    return $data['n'];
                }
            ],
        ],
    ]); ?>
</div>

<script>
    $(".Checkbox").click(function() {
        if (this.checked) {
            $(".TR :checkbox").prop("checked", true);
        } else {
            $(".TR :checkbox").prop("checked", false);
        }
    })

    var _span = $(".Read_LisJ>span")

    for (var i = 0; i < _span.length; i++) {
        _span.eq(i).click(function() {
            _span.removeClass("Read_Span")
            $(this).addClass("Read_Span")
            var d_type = $(this).attr('data-type');
            location.href="/site/index?start=&end=&daily_type="+d_type
        })
    }

    var myDate = new Date(); //获取今天日期
    var myYear = myDate.getFullYear() //获取年份
    myDate.setDate(myDate.getDate() - 7);
    var dateArray = [];
    var dateTemp;
    var flag = 1;
    for (var i = 0; i < 7; i++) {
        dateTemp = (myDate.getMonth() + 1) + "-" + myDate.getDate();
        dateArray.push(dateTemp);
        myDate.setDate(myDate.getDate() + flag);
    }
    var Start = myYear + "-" + dateArray[6]
    var S = "<?php echo $params['start'] ? date('Y-m-d',strtotime($params['start'])) : '';?>";
    var E = "<?php echo $params['end'] ? date('Y-m-d',strtotime($params['end'])) : '';?>";
    if(S == ''){
        $("#reservation").val(Start + " " + "-" + " " + Start)
    }else{
        $("#reservation").val(S + " " + "-" + " " + E)
    }
    $('#reservation').daterangepicker(null, function (start, end, label) {
        var s = moment(start).format("YYYY-MM-DD HH:mm:ss");
        var e = moment(end).format("YYYY-MM-DD HH:mm:ss");
        $("#reservation").val(S + " " + "-" + " " + E)
        location.href="/site/index?start="+s+"&end="+e+"&daily_type="+0
    });
</script>